package jianzhiOffer;

public class Num002 {
    public String addBinary(String a, String b) {
        StringBuilder sb = new StringBuilder();
        int i = a.length() - 1;
        int j = b.length() - 1;
        int push = 0;
        while(i >= 0 || j >= 0 || push != 0) {
            int bina = i >= 0 ? a.charAt(i) - '0' : 0;
            int binb = j >= 0 ? b.charAt(j) - '0' : 0;
            int sum = bina + binb + push;
            if(sum >= 2) {
                push = 1;
                sum -= 2;
            }else {
                push = 0;
            }
            sb.append(sum);
            i--;
            j--;
        }
        return sb.reverse().toString();
    }
}
